package com.codejoys.monitor;

public interface Constants {
    int AC_INPUT_OVER_VOLTAGE                   = 1 << 0;       // 交流输入过压
    int AC_INPUT_UNDER_VOLTAGE                  = 1 << 1;       // 交流输入欠压
    int AC_INPUT_OVER_VOLTAGE_DETACH            = 1 << 2;       // 交流输入过压脱离
    int DC_OUTPUT_OVER_VOLTAGE                  = 1 << 6;       // 直流输出过压
    int DC_OUTPUT_OVER_VOLTAGE_SHUTDOWN         = 1 << 7;       // 直流输出过压关机
    int DC_OUTPUT_UNDER_VOLTAGE                 = 1 << 8;       // 直流输出欠压
    int FAN_ERROR                               = 1 << 9;       // 风扇故障
    int ENV_OVER_TEMPERATURE_PROTECT            = 1 << 12;      // 环境温度过温保护
    int PFC_OVER_TEMPERATURE_PROTECT1           = 1 << 14;      // PFC过温保护1
    int PFC_OVER_TEMPERATURE_PROTECT2           = 1 << 15;      // PFC过温保护2
    int DC_OVER_TEMPERATURE_PROTECT1            = 1 << 16;      // 16: DC过温保护1
    int DC_OVER_TEMPERATURE_PROTECT2            = 1 << 17;      // 17：DC过温保护2
    int DUAL_EDGE_COMM_ERROR                    = 1 << 18;      // 18：原副边通信故障
    int PRIMARY_EDGE_ERROR                      = 1 << 20;      // 20: 原边故障
    int SECONDARY_EDGE_ERROR                    = 1 << 21;      // 21: 副边故障
    int POWER_ON_STATE                          = 1 << 25;      // 开关机状态

    int ERROR = AC_INPUT_OVER_VOLTAGE | AC_INPUT_UNDER_VOLTAGE | AC_INPUT_OVER_VOLTAGE_DETACH
            | DC_OUTPUT_OVER_VOLTAGE
            | DC_OUTPUT_OVER_VOLTAGE_SHUTDOWN
            | DC_OUTPUT_UNDER_VOLTAGE
            | FAN_ERROR
            | ENV_OVER_TEMPERATURE_PROTECT
            | PFC_OVER_TEMPERATURE_PROTECT1
            | PFC_OVER_TEMPERATURE_PROTECT2
            | DC_OVER_TEMPERATURE_PROTECT1
            | DC_OVER_TEMPERATURE_PROTECT2
            | DUAL_EDGE_COMM_ERROR
            | PRIMARY_EDGE_ERROR
            | SECONDARY_EDGE_ERROR;

    int CAN_MODULE_ON_FLAG          = 1;    // 打开模块
    int CAN_MODULE_OFF_FLAG         = 0;    // 关闭模块

    String CONFIG_KEY_ERROR_CHECK_TIME = "error_check_time";   // 老化错误检查时间间隔
    int CONFIG_VALUE_ERROR_CHECK_TIME = 5;   // 老化错误检查时间间隔

    String CONFIG_KEY_IS_ALARM_ON = "is_alarm_on";   // 是否开启报警
    int CONFIG_VALUE_ALARM_ON   = 1;   // 开启
    int CONFIG_VALUE_ALARM_OFF  = 2;   // 关闭

    String CONFIG_KEY_TPR_UPPER = "tpr_upper";   // 老化房温度报警上限
    String CONFIG_KEY_CABINET_TPR_UPPER = "cabinet_tpr_upper";   // 电源柜温度报警上限

    // 如何从SN里面计算设备型号  600F303xxxxxx  => (4, 4) => F303
    String CONFIG_KEY_MODEL_START = "model_start";  // SN型号起始位，为了方便用户计算，从1开始
    String CONFIG_KEY_MODEL_LEN = "model_len";      // SN型号长度

    int CONFIG_VALUE_MODEL_START    = 4;
    int CONFIG_VALUE_MODEL_LEN      = 4;

    enum Status {
        READY(1),      // 扫码，已就绪
        AGING(2),      // 老化中
        INTERRUPT(5),   // 中断（手动停止）
        FINISHED(3),   // 老化已完成
        ERROR(9);       // 老化错误

        private int value;
        Status(int i) {
            this.value = i;
        }

        public static String nameOf(Byte status) {
            if (status == 1) {
                return "已扫码";
            } else if (status == 2) {
                return "老化中";
            } else if (status == 3) {
                return "老化已完成";
            } else if (status == 5) {
                return "老化已中止";
            } else if (status == 9) {
                return "老化错误";
            }

            return "";
        }

        public int value() { return this.value; }

        public static boolean isError(int status) {
            return status == ERROR.value || status == INTERRUPT.value;
        }
    }
}
